package top.resty.erp.dao;

import org.apache.ibatis.annotations.*;
import top.resty.erp.domain.User;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年03月31 15:17
 */
@Mapper
public interface IUser {
	
	@Select("select distinct company from tb_user")
	public List<String> getCompanies();
	
	@Select({
			"<script>" ,
				"select * from tb_user where 1=1 " ,
				"<if test='user.company != null and user.company != \"\"'>and company = #{user.company} </if>" ,
				"<if test='user.contact != null and user.contact != \"\"'>and contact = #{user.contact} </if>" ,
				"<if test='user.location !=null and user.location != \"\"'>and location = #{user.location} </if>" ,
				"<if test='user.telephone != null and user.telephone != \"\"'>and telephone = #{user.telephone}</if>" ,
			"</script>"
	})
	public List<User> findUsersByCondition(@Param("user") User user);
	
	@Insert("insert into tb_user values(null,#{company},#{location},#{contact},#{telephone})")
	@Options(useGeneratedKeys = true,keyProperty = "id")
	public int savetUser(User user);
	
	@Select("select distinct location from tb_user where company = #{company}")
	List<String> getLocationNames(String company);
	
	@Select("select distinct contact from tb_user where location = #{param}")
	List<String> getContactNames(String param);
	
	@Select("select distinct telephone from tb_user where contact = #{param}")
	List<String> getTelephones(String param);
}
